package org.example.lyx2022.utils;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MybatisUtil {
    private static SqlSessionFactory sqlSessionFactory;

    // 使用@Autowired注解确保SqlSessionFactory被Spring注入
    @Autowired
    public MybatisUtil(SqlSessionFactory sqlSessionFactory) {
        MybatisUtil.sqlSessionFactory = sqlSessionFactory;
    }

    public static SqlSession getSqlSession() {
        return sqlSessionFactory.openSession();
    }
}